package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.order.MarketOrderGoods;
import com.cskaoyan.bean.order.wxbean.CommentBO;
import com.cskaoyan.bean.order.wxbean.OrderDetail;
import com.cskaoyan.bean.order.wxbean.OrderListVO;
import com.cskaoyan.bean.order.wxbean.submit.SubmitBO;
import com.cskaoyan.bean.order.wxbean.submit.SubmitVO;
import com.cskaoyan.service.wxorder_service.WXOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Hu
 * @create 2021-09-19 11:33
 * @Description
 */


@RestController
@RequestMapping("wx/order")
public class WXOrderController {

    @Autowired
    WXOrderService wxOrderService;

    //showTypex参数说明
    //0:全部 1:待付款 2:代发货 3:待收货 4:待评价
    @RequestMapping("list")
    //TODO:在此假定从shiro中获取了用户的id或者token//已经添加



    public BaseRespVo list(BaseParam baseParam, Integer showType, Integer userid) {
        BaseData<OrderListVO> baseData = wxOrderService.list(baseParam, showType, userid);
        return BaseRespVo.ok(baseData);
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody CommentBO comment) {
        wxOrderService.comment(comment);
        return BaseRespVo.ok();
    }



    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        OrderDetail orderDetail = wxOrderService.detail(orderId);
        return BaseRespVo.ok(orderDetail);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        int isDelete = wxOrderService.delete(orderId);
        if (isDelete == 0) {
            return BaseRespVo.ok("订单删除失败");
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        //SET status102
        int isCancel = wxOrderService.cancel(orderId);
        if (isCancel == 0) {
            return BaseRespVo.ok("订单取消失败");
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        //SET status401
        Integer orderId = (Integer) map.get("orderId");
        int isCancel = wxOrderService.confirm(orderId);
        if (isCancel == 0) {
            return BaseRespVo.ok("订单确认失败");
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        //SET status203
        Integer orderId = (Integer) map.get("orderId");
        int isCancel = wxOrderService.refund(orderId);
        if (isCancel == 0) {
            return BaseRespVo.ok("退款失败");
        }
        return BaseRespVo.ok();
    }

    //确认收货商品后 点击评价按钮 回显商品界面
    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId , Integer goodsId) {
        MarketOrderGoods orderGoodsVO = wxOrderService.goods(orderId, goodsId);
        return BaseRespVo.ok(orderGoodsVO);

    }

    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody SubmitBO submitBO) {
       SubmitVO submitVO = wxOrderService.submit(submitBO);
        return BaseRespVo.ok(submitVO);
    }


    @RequestMapping("prepay")
    public BaseRespVo submit(@RequestBody Map map) {
        Object orderId = map.get("orderId");
//        模拟付款处理
        return BaseRespVo.payFail();
    }





}
